﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using FeedNet;

namespace TestFeedNet
{
    /// <summary>
    /// Summary description for TestAtomParsing
    /// </summary>
    [TestClass]
    public class TestAtomParsing
    {

        Feed f;

        public TestAtomParsing()
        {
            string path = Path.Combine(Environment.CurrentDirectory, @"..\..\..\TestFeedNet\ATOM_testcase_hackety.org.txt");
            Feeder testFeeder = new Feeder();
            FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            f = testFeeder.getFeedFromStream(fs);
            fs.Close();
        }

        [TestMethod]
        public void testForParseSuccess()
        {
            Assert.IsNotNull(f);
        }

        [TestMethod]
        public void testAtomFeedTitle()
        {
            Assert.AreEqual("hackety org", f.title);
        }

        [TestMethod]
        public void testAtomFeedDescription()
        {
            Assert.AreEqual("filling your pockets & hat with code", f.description);
        }

        [TestMethod]
        public void testAtomFeedDate()
        {
            Assert.AreEqual(DateTime.Parse("2009-03-25T20:12:49Z"), f.last_modified);
        }

        [TestMethod]
        public void testAtomUrl()
        {
            Assert.AreEqual("http://hackety.org", f.url);
        }

        [TestMethod]
        public void testAtomNumberOfItems()
        {
            Assert.AreEqual(20, f.entries.Count);
        }

        [TestMethod]
        public void testAtomEntryTitleParsing()
        {
            Assert.AreEqual("Goodbye, Cruel Hello World", f.entries.First().title);
        }

        [TestMethod]
        public void testAtomEntryLink()
        {
            Assert.AreEqual("/2009/03/18/goodbyeCruelHelloWorld.html", f.entries.First().url);
        }

        [TestMethod]
        public void testAtomEntryGuid()
        {
            Assert.AreEqual("tag:hackety.org,2009:blogentry%2Fnews%2FgoodbyeCruelHelloWorld", f.entries.First().guid);
        }

        [TestMethod]
        public void testAtomEntrySummary()
        {
            Assert.AreEqual("<p>What ma", f.entries.First().description.Substring(0, 10));
        }

        [TestMethod]
        public void testAtomEntryContent()
        {
            Assert.AreEqual("<p>What ma", f.entries.First().content.Substring(0, 10));
        }
    }
}
